(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);

Utils = function(){
	this.lockDiv;
	this.oncontextmenu;
	this.onselectstart;
	this.ondragstart;
	this.onsource;
};
Utils.prototype = {
	getPath : function() {  
		var curWwwPath = window.document.location.href;
		var pathName = window.document.location.pathname;
		var pos = curWwwPath.indexOf(pathName);
		var localhostPath = curWwwPath.substring(0, pos);
		var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
		return (localhostPath + projectName);
	},
	getBase : function() {  
		var pathName = window.document.location.pathname;
		var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
		return projectName;
	},
	getPageSize : function() {  
		var xScroll, yScroll;  
		if (window.innerHeight && window.scrollMaxY) {    
			xScroll = window.innerWidth + window.scrollMaxX;  
			yScroll = window.innerHeight + window.scrollMaxY;  
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;  
			yScroll = document.body.scrollHeight;  
		} else {
			xScroll = document.body.offsetWidth;  
			yScroll = document.body.offsetHeight;  
		}  
		
		var windowWidth, windowHeight;  
		if (self.innerHeight) { 
			if(document.documentElement.clientWidth){  
				windowWidth = document.documentElement.clientWidth;   
			} else {  
				windowWidth = self.innerWidth;  
			}  
			windowHeight = self.innerHeight;  
		} else if (document.documentElement && document.documentElement.clientHeight) {  
			windowWidth = document.documentElement.clientWidth;  
			windowHeight = document.documentElement.clientHeight;  
		} else if (document.body) {
			windowWidth = document.body.clientWidth;  
			windowHeight = document.body.clientHeight;  
		}     
		
		if(yScroll < windowHeight){  
			pageHeight = windowHeight;  
		} else {   
			pageHeight = yScroll;  
		}  
		
		if(xScroll < windowWidth){     
			pageWidth = xScroll;          
		} else {  
			pageWidth = windowWidth;  
		}  
		
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);  
		return arrayPageSize;  
	},
        
	getClientHeight : function(){ 
		return document.body.clientHeight; 
	},
	
	getClientWidth :function(){ 
		return document.body.clientWidth; 
	},
	
	getTopPageSize : function() {  
		var xScroll, yScroll;  
		if (window.innerHeight && window.scrollMaxY) {    
			xScroll = window.innerWidth + window.scrollMaxX;  
			yScroll = window.innerHeight + window.scrollMaxY;  
		} else if (top.document.body.scrollHeight > top.document.body.offsetHeight){
			xScroll = top.document.body.scrollWidth;  
			yScroll = top.document.body.scrollHeight;  
		} else {
			xScroll = top.document.body.offsetWidth;  
			yScroll = top.document.body.offsetHeight;  
		}  
		
		var windowWidth, windowHeight;  
		if (self.innerHeight) { 
			if(top.document.documentElement.clientWidth){  
				windowWidth = top.document.documentElement.clientWidth;   
			} else {  
				windowWidth = self.innerWidth;  
			}  
			windowHeight = self.innerHeight;  
		} else if (top.document.documentElement && top.document.documentElement.clientHeight) {  
			windowWidth = top.document.documentElement.clientWidth;  
			windowHeight = top.document.documentElement.clientHeight;  
		} else if (top.document.body) {
			windowWidth = top.document.body.clientWidth;  
			windowHeight = top.document.body.clientHeight;  
		}     
		
		if(yScroll < windowHeight){  
			pageHeight = windowHeight;  
		} else {   
			pageHeight = yScroll;  
		}  
		
		if(xScroll < windowWidth){     
			pageWidth = xScroll;          
		} else {  
			pageWidth = windowWidth;  
		}  
		
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);  
		return arrayPageSize;  
	},
        
	getTopClientHeight : function(){ 
		return top.document.body.clientHeight; 
	},
	
	getTopClientWidth :function(){ 
		return top.document.body.clientWidth; 
	},
	
	stopEvent : function(){
		top.document.event.returnValue=false;
		event.returnValue=false;
	},
	
	lockScreen : function(){
		this.resumeLock(this.lockDiv);
		this.lockDiv = this.createLock();
		//禁止事件		
		this.oncontextmenu = top.document.oncontextmenu;
		this.onselectstart = top.document.onselectstart;
		this.ondragstart = top.document.ondragstart;
		this.onsource = top.document.onsource;
		top.document.oncontextmenu = this.stopEvent;//屏蔽鼠标左右键、
		top.document.onselectstart = this.stopEvent;//无法选择文字
		top.document.ondragstart = this.stopEvent;//禁止鼠标在网页上拖动
		top.document.onsource = this.stopEvent;
	},
	
	lockScreenByText : function(text,width,height){
		this.resumeLock(this.lockDiv);
		this.lockDiv = this.createLockByText(text,width,height);
		//禁止事件		
		this.oncontextmenu = top.document.oncontextmenu;
		this.onselectstart = top.document.onselectstart;
		this.ondragstart = top.document.ondragstart;
		this.onsource = top.document.onsource;
		top.document.oncontextmenu = this.stopEvent;//屏蔽鼠标左右键、
		top.document.onselectstart = this.stopEvent;//无法选择文字
		top.document.ondragstart = this.stopEvent;//禁止鼠标在网页上拖动
		top.document.onsource = this.stopEvent;
	},

	lockScreenByHtml : function(html,width,height){
		this.resumeLock(this.lockDiv);
		this.lockDiv = this.createLockByHtml(html,width,height);
		//禁止事件		
		this.oncontextmenu = top.document.oncontextmenu;
		this.onselectstart = top.document.onselectstart;
		this.ondragstart = top.document.ondragstart;
		this.onsource = top.document.onsource;
		top.document.oncontextmenu = this.stopEvent;//屏蔽鼠标左右键、
		top.document.onselectstart = this.stopEvent;//无法选择文字
		top.document.ondragstart = this.stopEvent;//禁止鼠标在网页上拖动
		top.document.onsource = this.stopEvent;
	},

	createLock : function(){
		var base = this.getBase();
		//return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading1.gif\" />",48,48);
		//return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading2.gif\" />",60,60);
		//return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading3.gif\" />",124,124);
		//return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading4.gif\" />",32,32);
		//return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading5.gif\" />",37,37);
		return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading6.gif\" />",105,104);
		//return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading7.gif\" />",66,66);
	},
	
	createLockByText : function(text,width,height){
		var base = this.getBase();
		return this.createLockByHtml("<img src=\""+base+"/style/utils/images/loading4.gif\" width=\"20\" height=\"20\" /><span style=\"font-size: 28px; color: #FF0000; font-weight: bold;\">"+text+"</span>",20+text.length*28,28);
	},
	
	createLockByHtml : function(html,width,height){
		var pageSize=this.getTopPageSize(); 
		var w=pageSize[0];
		var h=pageSize[1];
		var cw=this.getTopClientWidth();
		var ch=this.getTopClientHeight();
		
		//创建一层div遮盖，大小是窗口大小
		var div = $("<div>").css({
			position:"absolute",
			width:w,
			height:h,
			left:0,
			top:0,
			filter:"alpha(opacity=70)",
			"-moz-opacity":"0.7",
			"opacity":"0.7",
			"background-color":"#ffffff"
		});
		$(top.document.body).append(div);
		
		//显示文字
		if (!width || width<=0){
			width=cw;
		}
		if (!height || height<=0){
			height=ch;
		}
		$("<div>").css({
			position:"absolute",
			width:width,
			height:height,
			left:(cw-width)/2,
			top:(ch-height)/2
		}).html(html).appendTo(div).slideDown(10);
		
		//返回创建的层
		return div;
	},
	
	resumeScreen : function(){
		//删除层
		this.resumeLock(this.lockDiv);
		//恢复事件		
		top.document.oncontextmenu = this.oncontextmenu;
		top.document.onselectstart = this.onselectstart;
		top.document.ondragstart = this.ondragstart;
		top.document.onsource = this.onsource;
	},
	
	resumeLock : function(div){
		if (div){
			$(div).remove();
		}
	},
	
	getElementByName : function(elname){
		var els = document.getElementsByName(elname);
		if (els && els.length>0){
			return els[0];
		}else{
			return null;
		}
	},
	
	getElementValueByName : function(elname){
		var els = document.getElementsByName(elname);
		if (els && els.length>0){
			return els[0].value;
		}else{
			return "";
		}
	},
	
	setElementValueByName : function(elname, value){
		var els = document.getElementsByName(elname);
		if (els && els.length>0){
			els[0].value=value;
		}
	},
	
	getSelectedOptionByName : function(elname){
		var els = document.getElementsByName(elname);
		if (els && els.length>0){
			return els[0].options[els[0].selectedIndex];
		}else{
			return null;
		}
	},
	
	getSelectedValueByName : function(elname){
		var els = document.getElementsByName(elname);
		if (els && els.length>0){
			return els[0].options[els[0].selectedIndex].value;
		}else{
			return null;
		}
	},
	getRadioValueByName : function(elname){
		var radionum = document.getElementsByName(elname);
		for(var i=0; i<radionum.length; i++){
			if(radionum[i].checked){
				return radionum[i].value
			}
		}
		return "";
	},
	getSelectedTextByName : function(elname){
		var els = document.getElementsByName(elname);
		if (els && els.length>0){
			return els[0].options[els[0].selectedIndex].text;
		}else{
			return "";
		}
	},
	
	getStringLength : function(str){
		return str.replace(/[^\x00-\xff]/g,"aa").length;
	},
	
	dateStringToDate : function(s){
		var date = new Date(s.substring(0,4), parseInt(s.substring(4,6), 10) - 1, s.substring(6));
	    return date;
	},
	
	stringToDate : function(s){
	   var str = s.replace(/\//g,"-");
	   var array = str.split('-');
	   var date = new Date(array[0], parseInt(array[1], 10) - 1, array[2]);
	   return date;
	},
	
	dateToDateString : function(d){
		var s = d.getFullYear()+''+(d.getMonth() + 1)+''+d.getDate();
		return s;
	},
	
	dateToString : function(d){
		var s = d.getFullYear()+'-'+(d.getMonth() + 1)+'-'+d.getDate();
		return s;
	},
	
	timeToString : function(d){
		var s = d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
		return s;
	},

	dateTimeToString : function(d){
		var s = this.dateToString(d)+' '+this.timeToString(d);
		return s;
	},
	
	dateTimeFormat : function(oDate, fmt) {
		var o = {
			"M+": oDate.getMonth() + 1, //月份
			"d+": oDate.getDate(), //日
			"h+": oDate.getHours(), //小时
			"m+": oDate.getMinutes(), //分
			"s+": oDate.getSeconds(), //秒
			"q+": Math.floor((oDate.getMonth() + 3) / 3), //季度
			"S": oDate.getMilliseconds()//毫秒
		};
		if (/(y+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (oDate.getFullYear() + "").substr(4 - RegExp.$1.length));
		}
		for (var k in o) {
			if (new RegExp("(" + k + ")").test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			}
		}
		return fmt;
	},

	//合并相同内容的单元格
	autoRowSpan : function(tb,row,col){ 	
	         var lastValue=""; 
	        var value=""; 
	        var pos=1; 
	        for(var i=row;i<tb.rows.length;i++) 
	        { 
	            value = tb.rows[i].cells[col].innerText; 
	            if(lastValue == value) 
	            { 
	                tb.rows[i].deleteCell(col); 
	                tb.rows[i-pos].cells[col].rowSpan = tb.rows[i-pos].cells[col].rowSpan+1; 
	                pos++; 
	            }else{ 
	                lastValue = value; 
	                pos=1; 
	            } 
	        } 
	    }
	
};
	
	
Verify = function(){};
Verify.prototype = {
	isEmpty : function(elementName){
    	var el = __utils.getElementByName(elementName)
	    if (el.value==''){
	    	return true;
	    } else {
	    	return false;
	    }
	},
	idEmptyById:function (id){
		var el = document.getElementById(id);
		if (el.value==''){
	    	return true;
	    } else {
	    	return false;
	    }
	},
	isPositiveInt : function(s)	{
	    var r = /^[0-9]*[1-9][0-9]*$/;
	    return r.test(s);
	},
	
	isPositiveIntOrZero : function(s){
	    var r = /^\d+$/;
	    return r.test(s);
	},

	isPositiveFloat : function(s)	{
	    var r = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
	    return r.test(s);
	},
	
	isPositiveFloatOrZero : function(s){
	    var r = /^\d+(\.\d+)?$/;
	    return r.test(s);
	},

	isDate : function(s){
	   var str = s.replace(/\//g,"-");
	   var re = /^\d{4}-\d{1,2}-\d{1,2}$/;
	   if(re.test(str))
	   {
	       var array = str.split('-');
	       var date = new Date(array[0], parseInt(array[1], 10) - 1, array[2]);
	       if(!((date.getFullYear() == parseInt(array[0], 10))
	           && ((date.getMonth() + 1) == parseInt(array[1], 10))
	           && (date.getDate() == parseInt(array[2], 10))))
	       {
	           return false;
	       }
	       return true;
	   }
	   return false;
	},

	isTime : function(s){
	   var str = s;
	   var re = /^[0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
	   if(re.test(str))
	   {
		   var array = str.split(':');
	       if(parseInt(array[0], 10)>=24)
	       {
	           return false;
	       }
	       return true;
	   }
	   return false;
	},

	isDateTime : function(s){
       var array = s.split(' ');
       if (array.length==2){
	       return this.isDate(array[0]) && this.isTime(array[1]);
	   } else if (array.length==1){
	       return this.isDate(array[0]) || this.isTime(array[0]);
	   }
	   return false;
	},
	
	isDateString : function(s){
	   var str = s;
	   var re = /^\d{8}$/;
	   if(re.test(str))
	   {
	       var array = new Array();
	       array[0]=s.substring(0,4);
	       array[1]=s.substring(4,6);
	       array[2]=s.substring(6);
	       var date = new Date(array[0], parseInt(array[1], 10) - 1, array[2]);
	       if(!((date.getFullYear() == parseInt(array[0], 10))
	           && ((date.getMonth() + 1) == parseInt(array[1], 10))
	           && (date.getDate() == parseInt(array[2], 10))))
	       {
	           return false;
	       }
	       return true;
	   }
	   return false;
	},
	
	isPhoneNumber : function(s){
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证手机号码
	    return reg.test(s);
	},
	
	checkPhoneNumber: function(elementName, tips)	{
    	var el = __utils.getElementByName(elementName)
	    if (this.isPhoneNumber(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	},
	
	checkEmpty : function(elementName, tips){
    	var el = __utils.getElementByName(elementName)
	    if (el.value==''){
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return true;
	    } else {
	    	return false;
	    }
	},

	checkPositiveInt : function(elementName, tips)	{
    	var el = __utils.getElementByName(elementName)
	    if (this.isPositiveInt(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	},
	
	checkPositiveIntOrZero : function(elementName, tips){
    	var el = __utils.getElementByName(elementName)
	    if (this.isPositiveIntOrZero(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	},

	checkPositiveFloat : function(elementName, tips)	{
    	var el = __utils.getElementByName(elementName)
	    if (this.isPositiveFloat(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	},
	
	checkPositiveFloatOrZero : function(elementName, tips){
    	var el = __utils.getElementByName(elementName)
	    if (this.isPositiveFloatOrZero(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	},

	checkDate : function(elementName, tips){
    	var el = __utils.getElementByName(elementName)
	    if (this.isDate(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	},
	
	checkDateString : function(elementName, tips){
    	var el = __utils.getElementByName(elementName)
	    if (this.isDateString(el.value)){
	    	return true;
	    } else {
	    	__message.showInfo('提示',tips);
	    	el.focus();
	    	return false;
	    }
	}

};

Message = function(){};
Message.prototype = {
	checkMessage : function(url,params){
		$.get(url,params).done(function(data){
			if (data && $.trim(data)!="") {
				$.messager.show({
					title:'收到以下消息',
					msg:data,
					timeout:5000,
					showType:'slide'
				});
			}
		});
	},
	
	showMessage : function(title,tips) {
		$.messager.show({
			title:title,
			msg:tips,
			timeout:5000,
			showType:'slide'
		});
	},
	
	showInfo : function(title,tips,fn){
		var scrollTop = window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;
		$.messager.alert(title,tips,'info',fn);
		setTimeout(function(){
			$("body,html").animate({
				scrollTop:scrollTop
			},0);
		},5);
	},
	
	showConfirm : function(title,tips,fn){
		var scrollTop = window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;
		$.messager.confirm(title,tips, function(r){
			if (r) fn();
		});
		setTimeout(function(){
			$("body,html").animate({
				scrollTop:scrollTop
			},0);
		},5);
	}
};

var __utils = new Utils;
var __verify = new Verify();
var __message = new Message();
